package com.atguigu.gmall.order.listener;

import com.atguigu.gmall.order.config.DeadLetterMQConfig;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Auther 赵乾坤
 * @Date 2021-01-11 16:54
 *  * 订单接收消息的监听实现类
 */
@Component
public class OrderConsumer {

    @Autowired
    private OrderInfoService orderInfoService;
    //取消订单
    @RabbitListener(queues = DeadLetterMQConfig.QUEUE_ORDER_CANCEL2)
    public void receiverOrderCancelMessage(Long orderId, Channel chanel, Message message) throws Exception {

        System.out.println("orderId" +orderId);
        System.out.println("接收时间" + new Date());
        //取消订单
        orderInfoService.cancelOrder(orderId);
        chanel.basicAck(message.getMessageProperties().getDeliveryTag(), false);//不放在队列里

    }
}
